<template>
	<view class="bgView">
		<!-- v-show="current === 0" -->
		<view class="uni-padding-wrap uni-common-mt" v-for="(item, index) in reviewList" :key="index" v-if="reviewType != 5">
			<view class="uni-card">
				<view class="uni-card-content">
					<view class="uni-card-content-inner">
						<view class="user">
							<text>{{ item.type === '3' ? '请假人员: ' : '申请人员: ' }}</text>
							<text>{{ item.createUserName }}</text>
						</view>
						<view class="time">
							<text>{{ item.type === '3' ? '请假时间: ' : '申请时间: ' }}</text>
							<text>{{ item.type === '3' ? item.leaveStart+'~'+item.leaveEnd : item.createTime }}</text>
						</view>
						<view class="reason">
							<text>{{ item.type === '3' ? '请假原因: ' : '打卡位置: ' }}</text>
							<text>{{ item.type === '3' ? item.reason : item.address }}</text>
						</view>
						<view class="handleView" v-if="item.approvalStatus === '0'">
							<text class="pass" @click="handleAction('1', item)">通过</text>
							<text class="reject" @click="handleAction('2', item)">拒绝</text>
						</view>
						<view class="handleView" v-if="item.approvalStatus != '0'">
							<text class="pass" v-if="item.approvalStatus === '1'">已通过</text>
							<text class="reject" v-if="item.approvalStatus === '2'">未通过</text>
						</view>
					</view>
				</view>
			</view>
		</view>
		
		<view class="uni-padding-wrap uni-common-mt" v-for="(item, index) in localData" :key="index" v-if="reviewType == 5">
			<view class="uni-card">
				<view class="uni-card-content">
					<view class="uni-card-content-inner">
						<view class="user">
							<text>申请人员:</text>
							<text>{{ item.name }}</text>
						</view>
						<view class="time">
							<text> 申请时间: </text>
							<text>{{ item.createTime }}</text>
						</view>
						<view class="reason" v-for="(item1,index1) in item.json" :key='index1'>
							<text>位置{{index1+1}}：</text>
							<text>{{item1.address}}</text>
						</view>
						
						<view class="handleView" v-if="item.approval_status == 0">
							<text class="pass" @click="weizhiAccept(item.id, 1,'同意')">通过</text>
							<text class="reject" @click="handleAction(item.id, 2,'不同意')">拒绝</text>
						</view>
						<view class="handleView" v-if="item.approval_status != '0'">
							<text class="pass" v-if="item.approval_status === '1'">已通过</text>
							<text class="reject" v-if="item.approval_status === '2'">未通过</text>
						</view>
					</view>
				</view>
			</view>
		</view>
		
	</view>
</template>

<script>
// import uniLoadMore from '@/components/uni-load-more.vue';
import uniSegmentedControl from '@/components/uni-segmented-control/uni-segmented-control.vue';
export default {
	components: {
		uniSegmentedControl
	},
	data() {
		return {
			pageNo: 1,
			reviewType: '3',
			reviewList: [],
			localData: {}
		};
	},
	onLoad(event) {
		this.reviewType = event.reviewType;
		this.getList();
		if(event.reviewType == 5){
			this.weizhiCheck();
		}
		// this.weizhiAccept('625bc4d8-9ae3-11e9-b3be-0242ac11001d',0,'我认为合理');
	},
	onPullDownRefresh() {
		this.reviewList = new Array();
		this.pageNo = 1;
		this.getList();
	},
	onReachBottom() {
		this.pageNo++;
		this.getList();
	},
	methods: {
		getList() {
			uni.stopPullDownRefresh();
			this.$http.post('ac/xagrid/appAttenceService/getAuditList', { pageNo: this.pageNo, pageSize: 10, type: this.reviewType }).then(res => {
				this.reviewList = this.reviewList.concat(res.data.results);
			});
		},
		handleAction(type, item) {
			var that = this;
			if (type === '1') {
				uni.showModal({
					title: '提示',
					content: '确认通过' + item.createUserName + '的申请?',
					success: function(res) {
						if (res.confirm) {
							that.$http.post('ac/xagrid/appAttenceService/saveApproval', { id: item.id, approvalStatus: '1' }).then(res => {
								item.approvalStatus = '1';
							});
						}
					}
				});
			} else {
				uni.showModal({
					title: '提示',
					content: '确认拒绝' + item.createUserName + '的申请?',
					success: function(res) {
						if (res.confirm) {
							that.$http.post('ac/xagrid/appAttenceService/saveApproval', { id: item.id, approvalStatus: '2' }).then(res => {
								item.approvalStatus = '2';
							});
						}
					}
				});
			}
		},
		weizhiCheck() {
			let _this = this;
			this.$http.post('as/xagrid/appinspect/approvallist',{}).then(ret => {
				if (ret.errcode == 0) {
					let data = ret.data.results
					if (ret.data.results.length > 0) {
						for(let i=0;i<data.length;i++){
								let json = JSON.parse(data[i].addressjson);
								data[i].json = json;
						}
						_this.localData = data;
					}
				}
				console.log(ret, '位置审批');
			});
		},
		/**
		 * @param {Object} id 
		 * @param {Object} state 1-通过，0-未审批，2-拒绝
		 * @param {Object} reason
		 */
		weizhiAccept(id,state,reason){
			let _this = this
			this.$http.post('as/xagrid/appinspect/updateapply',{id:id,approval_status:state,reason:reason}).then(ret=>{
				if(ret.errcode == 0) {
					uni.showToast({
						title:'审核成功'
					})
					_this.weizhiCheck()
				}else{
					uni.showToast({
						title:ret.errcode,
						icon:'none'
					})
				}
			})
		}
	}
};
</script>

<style>
.bgView {
	width: 100%;
	height: 100%;
}

.handleView {
	width: 100%;
	height: 50upx;
	display: flex;
	flex-direction: row;
	justify-content: flex-end;
	margin-right: 20upx;
}

.pass {
	color: #09bb07;
	margin-right: 30upx;
}

.reject {
	color: red;
}
</style>
